#!/usr/bin/env python
# -*- coding: utf8 -*-

import sys,optparse,commands


def options():
    usage = '''Use like: 
%s -w 5,3,3
''' % __file__
   
    parser = optparse.OptionParser(usage)
    parser.add_option('-w','--warnning',dest='war',help='load avger')
    return parser

def main():
    parser = options()
    opt,args = parser.parse_args()
    if opt.war: 
        warload1,warload5,warload15 = opt.war.strip().split(',')
        f = open('/proc/loadavg','r')
        output = f.read().split()
        f.close()
        load1 = float(output[0])
        load5 = float(output[1])
        load15 = float(output[2])
        warload1 = float(warload1)
        warload5 = float(warload5)
        warload15 = float(warload15)
        print "Load 1minutes：%.2f,Load 5minutes：%.2f,Load 15minutes：%.2f|load1:%.2f:%.2f;load5:%.2f:%.2f;load15:%.2f:%.2f" % (load1,load5,load15,load1,warload1,load5,warload5,load15,warload15)

        if load1 > warload1 or load5 > warload5 or load15 > warload15:
            sys.exit(1)
        else:
            sys.exit(0)
    else:
        parser.print_help()

if __name__=="__main__":
    main()
